const express = require("express");
const Data = require("../models/Data")
const router = express.Router();

//新增顶级数据
router.post("/add", (req, res) => {
    let newD = new Data({
        dataName: req.body.dataName,
        sort: req.body.sort,
    })
    newD.save()
        .then(res.sendStatus(200))
})

//新增顶级数据中的children
router.post("/addChildren", (req, res) => {
    Data.updateOne({ dataName: req.body.dataName }, { $push: { "children": req.body.children } })
        .then(res.send("success"))
})

//获取 sort 为推荐的数据
router.get("/getTop", (req, res) => {
    Data.find({ sort: '推荐' }, { dataName: 1, children: 1 })
        .then(da => res.send({data:da,status:200}))
})

//获取书籍分类
router.get("/getBookClass", (req, res) => {
    Data.find({ dataName: "小说分类" }, { children: 1 })
        .then(thisCla => res.send({data:thisCla,status:200}))
})
module.exports = router